package hu.myandroidlife.activity;

import hu.myandroidlife.R;
import hu.myandroidlife.R.anim;
import hu.myandroidlife.R.id;
import hu.myandroidlife.R.layout;
import hu.myandroidlife.base.BaseActivity;
import hu.myandroidlife.util.WeiboDialogUtils;
import android.app.Dialog;
import android.os.Handler;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextView;

public class DialogActivity extends BaseActivity {

	private Button btnDialogLoading;
	private Button btnDialogExitBottom;
	private Dialog mWeiboDialog;
	
	
	private TextView mNoCancelPlanTv;
	private TextView mConfirmCancelPlanTv;
	private View mShowDialogLayout;
	private View mCancelDialogLayout;

	private final static int STOP_DIALOG = 10;

	private Handler mHandler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			switch (msg.what) {
			case STOP_DIALOG:
				WeiboDialogUtils.closeDialog(mWeiboDialog);
				break;

			default:
				break;
			}
		};
	};

	@Override
	protected int getLayoutId() {
		return R.layout.activity_dialog;
	}

	@Override
	protected void initView() {
		btnDialogLoading = $findViewById(R.id.btnDialogLoading);
		btnDialogExitBottom = $findViewById(R.id.btnDialogExitBottom);
		
		mShowDialogLayout = this.findViewById(R.id.dialog_show_layout);
		mCancelDialogLayout = this.findViewById(R.id.cancel_dialog_layout);
		mNoCancelPlanTv = (TextView)this.findViewById(R.id.no_cancel_plan_tv);
		mConfirmCancelPlanTv = (TextView)this.findViewById(R.id.confirm_cancel_plan_tv);
	}

	@Override
	protected void initListener() {
		btnDialogLoading.setOnClickListener(this);
		btnDialogExitBottom.setOnClickListener(this);
		mNoCancelPlanTv.setOnClickListener(this);
		mConfirmCancelPlanTv.setOnClickListener(this);
		
	}

	@Override
	protected void widgetClick(View v) {
		switch (v.getId()) {
		case R.id.btnDialogLoading:
			mWeiboDialog = WeiboDialogUtils.createLoadingDialog(
					DialogActivity.this, "加载中...");
			mHandler.sendEmptyMessageDelayed(STOP_DIALOG, 5000);
			break;
		case R.id.btnDialogExitBottom:
			showCancelDialogState(true);
			break;
		case R.id.no_cancel_plan_tv:
			showCancelDialogState(false);
			break;
		case R.id.confirm_cancel_plan_tv:
			finish();
		default:
			break;
		}
	}
	
	private void showCancelDialogState(boolean isVisable){
		Animation anim = null;
		if(isVisable){
		    anim = AnimationUtils.loadAnimation(this, R.anim.slide_bottom_to_up);
			mCancelDialogLayout.setAnimation(anim);
			mShowDialogLayout.setVisibility(View.VISIBLE);
			
			
		}else{
			anim = AnimationUtils.loadAnimation(this, R.anim.slide_up_to_bottom);
			mCancelDialogLayout.setAnimation(anim);
			mShowDialogLayout.setVisibility(View.GONE);
		}
	}
}
